﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace SCGILite.Helper
{
    public static class ActionHelper
    {
        public static Exception SafeExcute(Action action)
        {
            try
            {
                action();
                return null;
            }
            catch(Exception e)
            {
                return e;
            }
        }
        public static Exception SafeExcute<T>(Action<T> action, T v)
        {
            try
            {
                action(v);
                return null;
            }
            catch (Exception e)
            {
                return e;
            }
        }
        public static Exception SafeExcute<T1, T2>(Action<T1, T2> action, T1 v1, T2 v2)
        {
            try
            {
                action(v1, v2);
                return null;
            }
            catch (Exception e)
            {
                return e;
            }
        }
        public static Exception SafeExcute<T1, T2, T3>(Action<T1, T2, T3> action, T1 v1, T2 v2, T3 v3)
        {
            try
            {
                action(v1, v2, v3);
                return null;
            }
            catch (Exception e)
            {
                return e;
            }
        }
        public static Exception SafeExcute<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, T1 v1, T2 v2, T3 v3, T4 v4)
        {
            try
            {
                action(v1, v2, v3, v4);
                return null;
            }
            catch (Exception e)
            {
                return e;
            }
        }
    }
}
